The Data Science Workflow IV – Communicate
Charlotte Fresenius Privatuniversität
May 28, 2025
.qmd)In RStudio, we can create a new Quarto file by clicking on File > New File > Quarto Document. Give the document a fitting title and author and select PDF as the output format (for now). RStudio then creates a template .qmd file:
At the very top of the document – demarcated by three dashes (---) on either end – is the so-called YAML header:
YAML is a widely used language mainly used for providing configuration data.
With Quarto, it is used to define metadata about the document, such as (in this case) title, author and (output) format.
We can define many other things in the header than what is included in the template, e.g. theme, fontcolor or fig-width. A complete list of available YAML fields for PDF documents can be found here.
To run code inside a Quarto document, you need to put it inside a so-called code chunk. Such a code consists of four elements:
{r}).#|.The template contains an example of a code chunks with options:
echo: false prevents code, but not the results from appearing in the finished file. Use this when writing reports aimed at people who do not want to see the underlying R code.eval: false prevents code from being run. This is useful for displaying example code, or for disabling a large block of code without commenting each line.include: false runs the code, but doesn’t show the code or results in the final document. Use this for setup code (like loading libraries) that you do not want cluttering your report.message: false or warning: false prevents messages or warnings from appearing in the finished file.true.As you work more with Quarto, you will discover that some of the default chunk options do not fit your needs and you want to change them.
For example, consider a situation where you are writing a report for a non-technical audience. To hide the underlying R code, we would have to set echo: false in each and every chunk.
To avoid this, we can set the preferred options globally in the YAML header under execute. So, to achieve global code suppression, we would set:
These global code chunk options can be overridden locally in any chunk.
# Heading, ## Subheading and ### Subsubheading for section titles.
*italic* for text in italics.
**bold** for text in boldface.
- Item 1
- Item 2 for bullet point lists.
[Link text](https://quarto.org) for clickable links.
date field to the header and set it (literally) to today.Penguins in Antarctica.## Quarto to ## Data.palmerpenguins and ggplot2. For this chunk, set include: false.palmerpenguins package. Make sure to include a link to the website of the package, which can be found here.flipper_length_mm length against body_mass_g. Remove all other content from the template.After you did all that, your Quarto document should look something like this:
To compile (or render) your final report from this Quarto file, first save the file into an appropriate location on your computer.
Then, click on the button at the top of the screen. This will run all the code, and combine text, code and results in the desired output format:
palmerpenguins package:
Insert > Special Characters > Insert Emoji...).With all these changes, the visual editor should show something like this:
label, so that you can reference it in your text using its number (e.g., “see Figure 1”)..bib-file, so that references are properly formatted and listed automatically at the end of the document.label starting with fig-, e.g. fig-penguins1.fig-cap code chunk option, e.g. “A scatter plot of flipper length against body mass”.@fig-penguins1 or insert the cross reference via Insert > Cross Reference.Attributes tab.#fig-, e.g. #fig-cartoon@fig-cartoon (see next slide).Let’s say we wanted to cite the paper in which the penguin data was originally published. It can be found here.
To insert a citation in the visual editor, simply select Insert > Citation at the place where you want the citation to be. RStudio then gives you several options. The easiest way is to paste the DOI of the paper:
At the next rendering, Quarto will create a .bib file holding the added references, add the citation at the place where you have inserted it and append a list of references to the end of your document.
format in the YAML header.pdf: what we were using for our penguin report so far.html: an HTML document with more flexibility than a PDF (e.g. animations).docx: a Microsoft Word document.revealjs: an HTML-based presentation format allowing for interactivity, animations, dynamic content and much more.pptx: a Microsoft PowerPoint presentation.As you may have noticed, the penguin emojis we included into our Quarto document were not rendered into the output PDF. This is because the PDF output format cannot handle emojis.
To remedy that, let’s switch to html in the YAML header:
When we now click on , the report will be generated as an HTML and not as a PDF. Note how it changes in appearance slightly and now correctly displays the emojis we added earlier.
format to one of the presentation formats (e.g. revealjs or pptx) to generate a presentation, there are some special things to consider when doing that.revealjs or pptx:
##) demarcate slides, i.e. a new second level heading will create a new slide.#) indicate the beginning of a new section with a section title slide.A really basic presentation for the penguin example could look like this:
When rendered, this looks like this:
revealjs that showcases some more of the cool features that Quarto offers for presentations.Data Science and Data Analytics – The Data Science Workflow IV